include("shared.lua");
AddCSLuaFile("cl_init.lua");
AddCSLuaFile("shared.lua");
-- Setting up all the different properties of our melon.
ENT.Delay = 0.5;
ENT.Healthlol = 20;
ENT.FiringRange = 75;
ENT.NoMoveRange = 50;
ENT.MinRange = 0;
ENT.DeathRadius = 125;
ENT.DeathMagnitude = 30;
ENT.MovingForce = 25;
ENT.MelonModel = "models/props_phx/misc/soccerball.mdl";

-- Now we tell the base class to set up the melon. Pay attention - the variables must be defined BEFORE calling Setup().
function ENT:Initialize()
	self:Setup();
	if self.Mine == 1 then
	self.Entity:SetColor(255,255,255,60)
	end
if !self.Grav then 
self.MovingForce = (self.MovingForce * server_settings.Int( "WM_Flyingspeed", 0.75))
end
end

--What to do when we've found a target, and we've got the goahead to start attacking
function ENT:Attack ()
self.Healthlol = 0;

end

--Any other code you want to tag on to the end of the think function.
function ENT:Think ()
	if self.Mine ~= nil && self.Mine == 1 then
	if self.asploded then return end
	if WMPause == true then return end
	local entz = ents.FindByClass("info_target");
	for k, v in pairs(entz) do
		if v.Warmelon then
		local dist = v:GetPos():Distance(self.Entity:GetPos());
			if (dist<100 && v.Team ~= self.Team && v:GetParent():GetTable().asploded ~= true) then
			self.Healthlol = 0;
			end
		end
	end
	end
	if (self.Healthlol < 1 && !self.asploded) then
	local expl=ents.Create("env_explosion")
		self:BeforeDeathFunc();
		expl:SetPos(self.Entity:GetPos());
		expl:SetOwner(self.Entity);
		expl:SetKeyValue("iMagnitude",self.DeathMagnitude);
		expl:SetKeyValue("iRadiusOverride", self.DeathRadius);
		expl:Spawn();
		expl:Activate();
		expl:Fire("explode", "", 0);
		expl:Fire("kill","",0);
		self.asploded = true;
		constraint.RemoveAll (self.Entity);
		self.Entity:SetColor (0, 0, 0, 255);
		self.Entity:Fire ("kill", "", 3);
	end
	self:OtherThoughts();
	if not (self.asploded or WMPause == true) then
		if (CurTime()>self.Loltiem) then
			self.Loltiem = CurTime()+self.Delay;
			self:DoAttacks();
				if (self:WaterLevel() >0 ) then
				local drowntime = server_settings.Int( "WM_Drowntime", 10 );
					if (self.Marine) then
					elseif ( drowntime == 0) then
					else
					self.Healthlol = self.Healthlol - self.Maxlol/drowntime*self.Delay - 1;
					end
				end
		end
		if self.Move then
		self:DoMoves();
		self.Entity:NextThink(CurTime());
		else
		self.Entity:NextThink(CurTime()+self.Delay);
		end
	end
	return true;
end